﻿using System;
using System.Reflection;

namespace EnsureWeb.Share
{
    public static class Extensions
    {
        public static bool IsEmpty(this string text)
        {
            //if (string.IsNullOrEmpty(text))
            //    return true;
            if (text == null)
                return false;
            else if (text.Trim() == string.Empty)
                return true;

            return false;
        }
        
        public static T ConvertTo<T>(this object obj)
        {
            object result;
            try
            {
                result = Convert.ChangeType(obj, typeof(T), null);
            }
            catch
            {
                result = default(T);
            }

            return (T)result;
        }

        public static string Left(this string str, int length)
        {
            string s = "...";
            if (str.Length > length)
                return str.Substring(0, length - s.Length) + s;
            else
                return str;
        }

    }
}
